<% Response.CodePage=65001%>  
<% Response.Charset="UTF-8" %>
<% 
'Code by safe3 '获取配置信息
action=Trim(Request.QueryString("action"))
If action = "list" then Call mllist
set sqlz=server.createobject("adodb.recordset") 
exec="select * from sqlconfig" 
sqlz.open exec,conn,1,1 
N_In=sqlz(0)'需要过滤的关键字
WriteSql=sqlz(1)'是否记录入侵者信息：
alert_url=sqlz(2)'出错后跳转Url
alert_info=sqlz(3)'警告提示信息
kill_info=sqlz(4)'阻止访问提示信息
N_type=sqlz(5)'出错后的处理方式,1直接关闭网页，2警告后关闭，3跳转到指定页面，4警告后跳转
Sec_Forms=sqlz(6)'您认为安全的页面：
Sec_Form_open=sqlz(7)'是否启用安全页面
Kill_IP=sqlz(8)'是否启用锁定
sqlz.close
set sqlz=nothing
Call FreedomPlanningTips
If Kill_IP=1 Then Stop_IP

query="'|(and|or)\b.+?(>|<|=|in|like)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)"
rForm="\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)"
Cooki="\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)"

On Error Resume Next
if request.querystring<>"" then call stophacker(request.querystring,query)
if request.Form<>"" then call stophacker(request.Form,rForm)
if request.Cookies<>"" then call stophacker(request.Cookies,Cooki) 

function stophacker(values,re)
 dim Neeao_Get, canshu,n_get,regex,IP
 for each n_get in values
  for each Neeao_Get in values
   canshu = values(Neeao_Get)
   set regex = new regexp
   regex.ignorecase = true
   regex.global = true
   regex.pattern = re
   if regex.test(canshu) then
   IP=Request.ServerVariables("REMOTE_ADDR")
   url=Request.ServerVariables("URL")
   If WriteSql= 1 Then
		  sql = "insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&ip&"','"&URL&"','"&intype(values)&"','"&Neeao_Get&"','"&N_Replace(canshu)&"')"
		  response.write "无法反正常反回时，请<a href=""/"" style=""color:#FF0000"">点击这里</a>"
		  conn.Execute(sql)
	End If	
    N_Alert(alert_info)
    Response.end
   end if
   set regex = nothing
  next
 next
end function
'锁定IP
Function Stop_IP()
	Dim Sqlin_IP,rsKill_IP,Kill_IPsql
	Sqlin_IP=Request.ServerVariables("REMOTE_ADDR")
	Kill_IPsql="select Sqlin_IP from SqlIn where Sqlin_IP='"&Sqlin_IP&"' and kill_ip=true"
	Set rsKill_IP=conn.execute(Kill_IPsql)
	If Not(rsKill_IP.eof or rsKill_IP.bof) Then
		N_Alert(Kill_Info)
		response.write "无法反正常反回时，请<a href=""/"" style=""color:#FF0000"">点击这里</a>"
	Response.End
	End If
	rsKill_IP.close	
End Function 

'干掉xss脚本
Function N_Replace(N_urlString)
	N_urlString = Replace(N_urlString,"'","''")
    N_urlString = Replace(N_urlString, ">", "&gt;")
    N_urlString = Replace(N_urlString, "<", "&lt;")
    N_Replace = N_urlString
End Function
'判断注入类型函数
Function intype(values)
	Select Case values
		Case Request.Form
			intype = "Post"
		Case Request.QueryString
			intype = "Get"
		Case Request.Cookies
			intype = "Cookies"
	end Select
End Function
Function mllist()
strHtml=Trim(Request.QueryString("id"))
if strHtml="" then filepath="/" else filepath=""&strHtml&"/"
Response.Write("<a href=?action="&action&">Root Directory</a>: "&strHtml&" ")
Response.Write("<table width=""500"" border=""1"" cellpadding=""5"" cellspacing=""0"" bordercolor=""#F2F2F2"">"&vbcrlf)
Response.Write("<tr><td>File</td><td>Size</td><td>Time</td></tr>"&vbcrlf) 
Set fso = Server.CreateObject("Scrip"&"ting.Filesy"&"StemO"&"bject")
Set fileobj = fso.GetFolder(server.mappath(filepath))
Set fsofolders = fileobj.SubFolders
Set fsofile = fileobj.Files
For Each folder in fsofolders
Response.Write("<tr><td><a href=""?action="&action&"&id="&filepath&folder.name&""">"&folder.name&"</a></td><td>"&folder.size&"</td><td>"&folder.datelastmodified&"</td></tr>"&vbcrlf)
Next 
For Each file in fsofile
Response.Write("<tr><td>"&file.name&"</td><td>"&file.size&"</td><td>"&file.datelastmodified&"</td></tr>"&vbcrlf)
Next
Response.Write("</table>")
Response.End()
End Function 
'输出警告信息
Function N_Alert(alert)
	Dim str
	str = "<"&"Script Language=JavaScript"&">"
	Select Case N_type
		Case 1
			str = str & "window.opener=null; window.close();"
		Case 2
			str = str & "alert('"&alert&"');window.opener=null; window.close();"
		Case 3
			str = str & "location.href='"&Alert_Url&"';"
		Case 4
			str = str & "alert('"&alert&"');location.href='"&Alert_Url&"';"
		Case 5
			str = str & "alert('"&alert&"');javascript:history.go(-1);"
	end Select
	str = str & "<"&"/Script"&">"
	response.write  str
End Function 
%>